home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 52 / Amiga Format AFCD52 (Issue 136, May 2000).iso / -serious- / programming / other / mesa / mesa-aux / book.aux / accum.c < prev    next >
C/C++ Source or Header  |  2000-02-23  |  8KB  |  329 lines

  1. /*
  2.  * (c) Copyright 1993, Silicon Graphics, Inc.
  3.  * ALL RIGHTS RESERVED 
  4.  * Permission to use, copy, modify, and distribute this software for 
  5.  * any purpose and without fee is hereby granted, provided that the above
  6.  * copyright notice appear in all copies and that both the copyright notice
  7.  * and this permission notice appear in supporting documentation, and that 
  8.  * the name of Silicon Graphics, Inc. not be used in advertising
  9.  * or publicity pertaining to distribution of the software without specific,
  10.  * written prior permission. 
  11.  *
  12.  * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
  13.  * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
  14.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
  15.  * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
  16.  * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
  17.  * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
  18.  * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
  19.  * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
  20.  * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
  21.  * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
  22.  * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
  23.  * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
  24.  * 
  25.  * US Government Users Restricted Rights 
  26.  * Use, duplication, or disclosure by the Government is subject to
  27.  * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
  28.  * (c)(1)(ii) of the Rights in Technical Data and Computer Software
  29.  * clause at DFARS 252.227-7013 and/or in similar or successor
  30.  * clauses in the FAR or the DOD or NASA FAR Supplement.
  31.  * Unpublished-- rights reserved under the copyright laws of the
  32.  * United States.  Contractor/manufacturer is Silicon Graphics,
  33.  * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
  34.  *
  35.  * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
  36.  */
  37. /*
  38.  * accum.c
  39.  */
  40. #include <GL/gl.h>
  41. #include <GL/glu.h>
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <GL/glaux.h>
  45.  
  46. GLsizei width, height;
  47.  
  48. void myinit(void)
  49. {
  50.   GLfloat ambient[] =
  51.   {0.4, 0.4, 0.4, 1.0};
  52.   GLfloat diffuse[] =
  53.   {1.0, 1.0, 1.0, 1.0};
  54.   GLfloat specular[] =
  55.   {1.0, 1.0, 1.0, 1.0};
  56.   GLfloat position[] =
  57.   {0.0, 2.0, 2.0, 0.0};
  58.   GLfloat mat_ambient[] =
  59.   {0.2, 0.2, 0.2, 1.0};
  60.   GLfloat mat_diffuse[] =
  61.   {0.7, 0.7, 0.7, 1.0};
  62.   GLfloat mat_specular[] =
  63.   {0.9, 0.9, 0.9, 1.0};
  64.   GLfloat mat_shininess[] =
  65.   {50.0};
  66.   GLfloat lmodel_ambient[] =
  67.   {0.2, 0.2, 0.2, 1.0};
  68.  
  69.   glEnable(GL_DEPTH_TEST);
  70.   glDepthFunc(GL_LESS);
  71.  
  72.   glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
  73.   glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
  74.   glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
  75.   glLightfv(GL_LIGHT0, GL_POSITION, position);
  76.  
  77.   glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  78.   glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  79.   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  80.   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
  81.  
  82.   glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
  83.  
  84.   glEnable(GL_LIGHTING);
  85.   glEnable(GL_LIGHT0);
  86.   glEnable(GL_AUTO_NORMAL);
  87.   glEnable(GL_NORMALIZE);
  88.  
  89.   glEnable(GL_CULL_FACE);
  90.   glCullFace(GL_FRONT);
  91.  
  92.   glClearAccum(0.0, 0.0, 0.0, 0.0);
  93. }
  94.  
  95. #define ACSIZE 16
  96.  
  97. GLfloat dx[ACSIZE], dy[ACSIZE];
  98.  
  99. GLfloat jitter3[3][2] =
  100. {
  101.   {0.5, 0.5},
  102.   {1.35899e-05, 0.230369},
  103.   {0.000189185, 0.766878},
  104. };
  105.  
  106. GLfloat jitter11[11][2] =
  107. {
  108.   {0.5, 0.5},
  109.   {0.406537, 0.135858},
  110.   {0.860325, 0.968558},
  111.   {0.680141, 0.232877},
  112.   {0.775694, 0.584871},
  113.   {0.963354, 0.309056},
  114.   {0.593493, 0.864072},
  115.   {0.224334, 0.415055},
  116.   {0.0366643, 0.690884},
  117.   {0.139685, 0.0313988},
  118.   {0.319861, 0.767097},
  119. };
  120.  
  121. GLfloat jitter16[16][2] =
  122. {
  123.   {0.4375, 0.4375},
  124.   {0.1875, 0.5625},
  125.   {0.9375, 1.1875},
  126.   {0.4375, 0.9375 - 1},
  127.   {0.6875, 0.5625},
  128.   {0.1875, 0.0625},
  129.   {0.6875, 0.3125},
  130.   {0.1875, 0.3125},
  131.   {0.4375, 0.1875},
  132.   {0.9375 - 1, 0.4375},
  133.   {0.6875, 0.8125},
  134.   {0.4375, 0.6875},
  135.   {0.6875, 0.0625},
  136.   {0.9375, 0.9375},
  137.   {1.1875, 0.8125},
  138.   {0.9375, 0.6875},
  139. };
  140.  
  141. GLfloat jitter29[29][2] =
  142. {
  143.   {0.5, 0.5},
  144.   {0.498126, 0.141363},
  145.   {0.217276, 0.651732},
  146.   {0.439503, 0.954859},
  147.   {0.734171, 0.836294},
  148.   {0.912454, 0.79952},
  149.   {0.406153, 0.671156},
  150.   {0.0163892, 0.631994},
  151.   {0.298064, 0.843476},
  152.   {0.312025, 0.0990405},
  153.   {0.98135, 0.965697},
  154.   {0.841999, 0.272378},
  155.   {0.559348, 0.32727},
  156.   {0.809331, 0.638901},
  157.   {0.632583, 0.994471},
  158.   {0.00588314, 0.146344},
  159.   {0.713365, 0.437896},
  160.   {0.185173, 0.246584},
  161.   {0.901735, 0.474544},
  162.   {0.366423, 0.296698},
  163.   {0.687032, 0.188184},
  164.   {0.313256, 0.472999},
  165.   {0.543195, 0.800044},
  166.   {0.629329, 0.631599},
  167.   {0.818263, 0.0439354},
  168.   {0.163978, 0.00621497},
  169.   {0.109533, 0.812811},
  170.   {0.131325, 0.471624},
  171.   {0.0196755, 0.331813},
  172. };
  173.  
  174. GLfloat jitter90[90][2] =
  175. {
  176.   {0.5, 0.5},
  177.   {0.784289, 0.417355},
  178.   {0.608691, 0.678948},
  179.   {0.546538, 0.976002},
  180.   {0.972245, 0.270498},
  181.   {0.765121, 0.189392},
  182.   {0.513193, 0.743827},
  183.   {0.123709, 0.874866},
  184.   {0.991334, 0.745136},
  185.   {0.56342, 0.0925047},
  186.   {0.662226, 0.143317},
  187.   {0.444563, 0.928535},
  188.   {0.248017, 0.981655},
  189.   {0.100115, 0.771923},
  190.   {0.593937, 0.559383},
  191.   {0.392095, 0.225932},
  192.   {0.428776, 0.812094},
  193.   {0.510615, 0.633584},
  194.   {0.836431, 0.00343328},
  195.   {0.494037, 0.391771},
  196.   {0.617448, 0.792324},
  197.   {0.688599, 0.48914},
  198.   {0.530421, 0.859206},
  199.   {0.0742278, 0.665344},
  200.   {0.979388, 0.626835},
  201.   {0.183806, 0.479216},
  202.   {0.151222, 0.0803998},
  203.   {0.476489, 0.157863},
  204.   {0.792675, 0.653531},
  205.   {0.0990416, 0.267284},
  206.   {0.776667, 0.303894},
  207.   {0.312904, 0.296018},
  208.   {0.288777, 0.691008},
  209.   {0.460097, 0.0436075},
  210.   {0.594323, 0.440751},
  211.   {0.876296, 0.472043},
  212.   {0.0442623, 0.0693901},
  213.   {0.355476, 0.00442787},
  214.   {0.391763, 0.361327},
  215.   {0.406994, 0.696053},
  216.   {0.708393, 0.724992},
  217.   {0.925807, 0.933103},
  218.   {0.850618, 0.11774},
  219.   {0.867486, 0.233677},
  220.   {0.208805, 0.285484},
  221.   {0.572129, 0.211505},
  222.   {0.172931, 0.180455},
  223.   {0.327574, 0.598031},
  224.   {0.685187, 0.372379},
  225.   {0.23375, 0.878555},
  226.   {0.960657, 0.409561},
  227.   {0.371005, 0.113866},
  228.   {0.29471, 0.496941},
  229.   {0.748611, 0.0735321},
  230.   {0.878643, 0.34504},
  231.   {0.210987, 0.778228},
  232.   {0.692961, 0.606194},
  233.   {0.82152, 0.8893},
  234.   {0.0982095, 0.563104},
  235.   {0.214514, 0.581197},
  236.   {0.734262, 0.956545},
  237.   {0.881377, 0.583548},
  238.   {0.0560485, 0.174277},
  239.   {0.0729515, 0.458003},
  240.   {0.719604, 0.840564},
  241.   {0.325388, 0.7883},
  242.   {0.26136, 0.0848927},
  243.   {0.393754, 0.467505},
  244.   {0.425361, 0.577672},
  245.   {0.648594, 0.0248658},
  246.   {0.983843, 0.521048},
  247.   {0.272936, 0.395127},
  248.   {0.177695, 0.675733},
  249.   {0.89175, 0.700901},
  250.   {0.632301, 0.908259},
  251.   {0.782859, 0.53611},
  252.   {0.0141421, 0.855548},
  253.   {0.0437116, 0.351866},
  254.   {0.939604, 0.0450863},
  255.   {0.0320883, 0.962943},
  256.   {0.341155, 0.895317},
  257.   {0.952087, 0.158387},
  258.   {0.908415, 0.820054},
  259.   {0.481435, 0.281195},
  260.   {0.675525, 0.25699},
  261.   {0.585273, 0.324454},
  262.   {0.156488, 0.376783},
  263.   {0.140434, 0.977416},
  264.   {0.808155, 0.77305},
  265.   {0.282973, 0.188937},
  266. };
  267.  
  268. void loaddxdy(void)
  269. {
  270.   long i;
  271.  
  272.   for (i = 0; i < ACSIZE; i++) {
  273.     dx[i] = jitter16[i][0] * 10 / width;
  274.     dy[i] = jitter16[i][1] * 10 / height;
  275.   }
  276. }
  277.  
  278. void display(void)
  279. {
  280.   int i;
  281.  
  282.   glClear(GL_ACCUM_BUFFER_BIT);
  283.   loaddxdy();
  284.   for (i = 0; i < (ACSIZE); i++) {
  285.     printf("Pass %d\n", i);
  286.     glPushMatrix();
  287.     glTranslatef(dx[i], dy[i], 0.0);
  288.     glRotatef(45.0, 1.0, 1.0, 1.0);
  289.     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
  290.     auxSolidTeapot(1.0);
  291.     glPopMatrix();
  292.     glAccum(GL_ACCUM, 1.0 / (ACSIZE));
  293.   }
  294.   printf("final job\n");
  295.   glAccum(GL_RETURN, 1.0);
  296.   printf("done\n");
  297.   glFlush();
  298. }
  299.  
  300. void myReshape(int w, int h)
  301. {
  302.   width = w;
  303.   height = h;
  304.   glViewport(0, 0, w, h);
  305.   glMatrixMode(GL_PROJECTION);
  306.   glLoadIdentity();
  307.   if (w <= h)
  308.     glOrtho(-3.0, 3.0, -3.0 * (GLfloat) h / (GLfloat) w,
  309.         3.0 * (GLfloat) h / (GLfloat) w, -15.0, 15.0);
  310.   else
  311.     glOrtho(-3.0 * (GLfloat) w / (GLfloat) h,
  312.         3.0 * (GLfloat) w / (GLfloat) h, -3.0, 3.0, -15.0, 15.0);
  313.   glMatrixMode(GL_MODELVIEW);
  314.   glLoadIdentity();
  315. }
  316.  
  317. int main(int argc, char **argv)
  318. {
  319.   auxInitDisplayMode(AUX_SINGLE | AUX_RGB
  320.              | AUX_ACCUM | AUX_DEPTH);
  321.   auxInitPosition(0, 0, 300, 300);
  322.   if (!auxInitWindow(argv[0]))
  323.     auxQuit();
  324.   myinit();
  325.   auxReshapeFunc(myReshape);
  326.   auxMainLoop(display);
  327.   return 0;
  328. }
  329.